(function () {
    let stick = document.querySelector('.stick');
    let pencil = document.querySelector(".pencil");
    let arrows = document.querySelector(".arrows");
    // 获取滚动条事件
    window.onscroll = function () {
        let scrollHigh = document.documentElement.scrollTop || document.body.scrollTop;
        if (scrollHigh > 40) {
            pencil.classList.add("animate1");
        };
        if (scrollHigh < 40) {
            pencil.classList.remove("animate1");
        }
    }
    // 点击后置顶
    arrows.onclick = function () {
        let time = setInterval(function () {
            let top = window.pageYOffset;
            let step = Math.ceil(top / 50);
            window.scroll(0, top - step);
            if (top == 0) {
                clearInterval(time)
            }
        })
    }

    //  铅笔点击事件
    let clickPopup = document.querySelector(".click-popup");
    pencil.onclick = function () {
        // 点击时显示
        clickPopup.style.display = "flex";
        pencil.style.display = "none";
        stick.style.display = "none";
        // 点击其他地方后隐藏
        clickPopup.onclick = function (event) {
            pencil.style.display = "flex";
            stick.style.display = "flex";
            if (event.target.className === "click-popup") {
                clickPopup.style.display = "none";
            }
        }
    }

    // 点击图片,链接,笔,选择图标时的操作
    let clickRound = document.querySelector(".click-round");
    let clickRound1 = document.querySelector(".click-round1");
    // let clickRound2 = document.querySelector(".click-round2");
    let clickRound3 = document.querySelector(".click-round3");
    let popup1 = document.querySelector(".popup1");
    popup1.onclick = function (event) {
        clickPopup.style.display = "none";
        // console.log(event.target.className);
        if (event.target.className === "picture caddy" || event.target.className === "iconfont icon-shangchuantupian") {
            clickRound.style.display = "flex";
        } else if (event.target.className === "tick caddy" || event.target.className === "iconfont icon-duigou") {
            clickRound1.style.display = "flex";
        } else if (event.target.className === "article caddy" || event.target.className === "iconfont icon-bianji") {
            // 获取用户信息
            axios.get('/api/getAuser')
                .then(res => {
                    console.log(res)
                    let eid = res.data.userinfo.uid;
                    if (res.data.code === 1) {
                        window.location.href = `./article.html?eid=${eid}`;
                    }
                })
                .catch(err => {
                    console.error(err);
                })

        } else if (event.target.className === "share caddy" || event.target.className === "iconfont icon-lianjie") {
            clickRound3.style.display = "flex";
        }
    }

    // 每个关闭标签绑定点击事件
    let close = document.querySelectorAll("#close");
    close.forEach(item => {
        item.onclick = function () {
            item.parentElement.parentElement.parentElement.parentElement.style.display = "none";
            pencil.style.display = "flex";
            stick.style.display = "flex";
        }
    })

})();